package com.sikaryofficial.backend.manager;

import com.sikaryofficial.backend.domain.mapping.Ip2LocationDataMapping;
import com.sikaryofficial.backend.service.address.Ip2LocationService;
import com.sikaryofficial.system.api.model.ip.IpLocationVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * @author : qinjinyuan
 * @desc : IP国家信息服务
 * @date : 2023/10/30 15:39
 */
@Component
@Slf4j
@SuppressWarnings(value = "unchecked")
public class Ip2LocationManager {

    @Value("${ip2location.ip2location-lite-db1_path}")
    private String db1Path;

    @Autowired
    private Ip2LocationService ip2LocationService;

    public IpLocationVO getGeographyInfo(String iPAddress) {
        return ip2LocationService.getGeographyInfo(iPAddress);
    }

    /**
     * 通过IP获取国家、区域、城市数据
     *
     * @param iPAddress
     * @return
     */
    public IpLocationVO getCountryAreaVO(String iPAddress) {
        return Ip2LocationDataMapping.INSTANCE.cover(ip2LocationService.getCountryAreaVO(iPAddress));
    }
}
